Muestra de widgets

Author

R1ck7

Widget’s R

Librerías y directorios

# LoadLibrary
library(tidyverse)
library(magrittr)
library(haven)
library(leaflet)
library(terra)
library(raster)
library(janitor)
library(sf)

Creación de base de datos

cong_urb <- file.path("E:\\BackUp SSD Acer\\Mapas\\QGis_ENAHOgeoserver\\ConglomeradoUrbano.shp")
cong_rur <- file.path("E:\\BackUp SSD Acer\\Mapas\\QGis_ENAHOgeoserver\\ConglomeradoRural.shp")
db_urb <- read_sf(cong_urb)
db_rur <- read_sf(cong_rur)
# Base de datos: Conglomerados Urbanos
db_urb %>% glimpse()
Rows: 4,066
Columns: 20
$ UBIGEO     <chr> "010101", "010201", "010201", "010701", "010701", "010502",…
$ IDCCPP     <chr> "0001", "0001", "0001", "0001", "0001", "0001", "0001", "00…
$ NOMCCPP    <chr> "CHACHAPOYAS", "BAGUA", "BAGUA", "BAGUA GRANDE", "BAGUA GRA…
$ OBJECTID   <dbl> 16676, 16677, 16678, 16679, 16680, 16681, 16682, 16683, 166…
$ CODDPTO    <chr> "01", "01", "01", "01", "01", "01", "01", "02", "02", "02",…
$ CODPROV    <chr> "01", "02", "02", "07", "07", "05", "05", "18", "18", "18",…
$ CODDIST    <chr> "01", "01", "01", "01", "01", "02", "10", "01", "01", "01",…
$ CODZONA    <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
$ SUFZONA    <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
$ CONGLOM_20 <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
$ ID         <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
$ CONGLO_6   <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
$ CONGLO_8   <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
$ CONGLOME   <chr> "005007", "005027", "005030", "005039", "005045", "005061",…
$ ANIO       <dbl> 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022,…
$ MES        <chr> "02", "08", "01", "05", "06", "03", "10", "06", "02", "08",…
$ VIVIENDAS_ <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
$ Shape.STLe <dbl> 0.011999920, 0.025454417, 0.012553168, 0.009721920, 0.02947…
$ ODEI       <chr> "01", "01", "01", "01", "01", "01", "01", "02", "02", "02",…
$ geometry   <MULTIPOLYGON [°]> MULTIPOLYGON (((-77.87629 -..., MULTIPOLYGON (…
# Base de datos: Conglomerados Rurales
db_rur %>% glimpse()
Rows: 1,279
Columns: 10
$ OBJECTID_1 <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, …
$ OBJECTID   <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, …
$ ENAHO      <chr> "005073", "005074", "005076", "005079", "005086", "005087",…
$ nconglome1 <chr> "00647500", "00648000", "00650100", "00651000", "00655100",…
$ MES        <chr> "04", "06", "11", "01", "06", "09", "12", "05", "01", "09",…
$ CONGLOME   <chr> "005073", "005074", "005076", "005079", "005086", "005087",…
$ Shape_Leng <dbl> 2.0548449, 2.4212556, 0.8357599, 0.8751766, 0.6982579, 0.86…
$ Shape.STAr <dbl> 0.166226950, 0.175475139, 0.035886604, 0.042730806, 0.01638…
$ Shape.STLe <dbl> 2.0548449, 2.4212556, 0.8357599, 0.8751766, 0.6982579, 0.86…
$ geometry   <MULTIPOLYGON [°]> MULTIPOLYGON (((-77.20622 -..., MULTIPOLYGON (…

Mostrar en Mapa

Conglomerados Urbanos

db_urb %>% head()
Simple feature collection with 6 features and 19 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -78.5324 ymin: -6.22998 xmax: -77.87195 ymax: -5.628108
Geodetic CRS:  WGS 84
# A tibble: 6 × 20
  UBIGEO IDCCPP NOMCCPP       OBJECTID CODDPTO CODPROV CODDIST CODZONA SUFZONA
  <chr>  <chr>  <chr>            <dbl> <chr>   <chr>   <chr>   <chr>   <chr>  
1 010101 0001   CHACHAPOYAS      16676 01      01      01      <NA>    <NA>   
2 010201 0001   BAGUA            16677 01      02      01      <NA>    <NA>   
3 010201 0001   BAGUA            16678 01      02      01      <NA>    <NA>   
4 010701 0001   BAGUA GRANDE     16679 01      07      01      <NA>    <NA>   
5 010701 0001   BAGUA GRANDE     16680 01      07      01      <NA>    <NA>   
6 010502 0001   CAMPORREDONDO    16681 01      05      02      <NA>    <NA>   
# ℹ 11 more variables: CONGLOM_20 <chr>, ID <dbl>, CONGLO_6 <chr>,
#   CONGLO_8 <chr>, CONGLOME <chr>, ANIO <dbl>, MES <chr>, VIVIENDAS_ <dbl>,
#   Shape.STLe <dbl>, ODEI <chr>, geometry <MULTIPOLYGON [°]>
leaflet() %>%
  addProviderTiles(as.character(providers[152])) %>%
  addPolygons(
    data = db_urb,
    color = "orange",
    popup = ~ paste0("<b>", NOMCCPP, "</b><hr>", CODDIST)
  )  

Conglomerados Rurales

db_rur %>% head()
Simple feature collection with 6 features and 9 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -78.64203 ymin: -5.45624 xmax: -77.09536 ymax: -3.553206
Geodetic CRS:  WGS 84
# A tibble: 6 × 10
  OBJECTID_1 OBJECTID ENAHO  nconglome1 MES   CONGLOME Shape_Leng Shape.STAr
       <dbl>    <dbl> <chr>  <chr>      <chr> <chr>         <dbl>      <dbl>
1          1        1 005073 00647500   04    005073        2.05      0.166 
2          2        2 005074 00648000   06    005074        2.42      0.175 
3          3        3 005076 00650100   11    005076        0.836     0.0359
4          4        4 005079 00651000   01    005079        0.875     0.0427
5          5        5 005086 00655100   06    005086        0.698     0.0164
6          6        6 005087 00656400   09    005087        0.869     0.0409
# ℹ 2 more variables: Shape.STLe <dbl>, geometry <MULTIPOLYGON [°]>
db_rur %>%
  group_by(MES) %>%
  summarise(n = n())
Simple feature collection with 12 features and 2 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -81.32823 ymin: -18.35093 xmax: -68.65228 ymax: -0.4787102
Geodetic CRS:  WGS 84
# A tibble: 12 × 3
   MES       n                                                          geometry
   <chr> <int>                                                <MULTIPOLYGON [°]>
 1 01      118 (((-74.29333 -13.03272, -74.30165 -13.02115, -74.32252 -12.98314…
 2 02      106 (((-71.88085 -16.58274, -71.88159 -16.57556, -71.88161 -16.57367…
 3 03       98 (((-76.50917 -12.13829, -76.57209 -12.10403, -76.57842 -12.09466…
 4 04      104 (((-79.97127 -6.472412, -79.97284 -6.480812, -79.97238 -6.497951…
 5 05      104 (((-77.40511 -5.915302, -77.40875 -5.918237, -77.43221 -5.937155…
 6 06      108 (((-77.37949 -8.760411, -77.39473 -8.752854, -77.39826 -8.7515, …
 7 07      108 (((-73.83491 -12.59931, -73.84778 -12.59736, -73.87649 -12.59301…
 8 08      109 (((-78.15218 -7.769233, -78.21954 -7.725852, -78.22754 -7.720705…
 9 09      105 (((-73.86223 -13.15337, -73.9345 -13.12295, -73.99428 -13.09779,…
10 10      110 (((-77.64295 -8.067123, -77.54166 -8.025346, -77.52225 -8.017341…
11 11      105 (((-72.32708 -16.14136, -72.33831 -16.13673, -72.34037 -16.1384,…
12 12      104 (((-69.71569 -15.12805, -69.68355 -15.09161, -69.66682 -15.06244…
leaflet() %>%
  addProviderTiles(as.character(providers[152])) %>%
  addPolygons(
    data = db_rur %>% filter(MES %in% c("01", "02", "03", "04")),
    color = "purple",
    popup = ~ paste0("<b>", CONGLOME, "</b><hr>", MES)
  ) %>%
  addPolygons(
    data = db_rur %>% filter(MES %in% c("05", "06", "07", "08")),
    color = "blue",
    popup = ~ paste0("<b>", CONGLOME, "</b><hr>", MES)
  ) %>%
  addPolygons(
    data = db_rur %>% filter(MES %in% c("09", "10", "11", "12")),
    color = "green",
    popup = ~ paste0("<b>", CONGLOME, "</b><hr>", MES)
  )

FIN